package com.mentaleye.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.mentaleye.bean.StudentsBean;
import com.mentaleye.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.dal.dao.StudentsDao;
import com.mentaleye.dal.model.Students;
import com.mentaleye.dal.model.StudentsExample;
import com.mentaleye.dal.model.StudentsExample.Criteria;
import com.mentaleye.service.StudentsService;

@Service
public class StudentsServiceImpl implements StudentsService{

	@Autowired private StudentsDao dataDao;

	@Override
	public boolean insertData(Students data) {
		return this.dataDao.insertData(data);
	}

	@Override
	public boolean insertByList(List<Students> dataList) {
		return this.dataDao.insertByList(dataList);
	}
	
	@Override
	public boolean updateData(Students data) {
		return this.dataDao.updateData(data);
	}
	
	@Override
	public boolean updateStateById(Students data) {
		StudentsExample example=new StudentsExample();
		Criteria criteria = example.createCriteria();
		criteria.andIdEqualTo(data.getId());
		return this.dataDao.updateDataBySelective(data, example);
	}
	
	@Override
	public boolean updateStateByMap(Map<String, Object> map) {
		return this.dataDao.updateStateByMap(map);
	}

	@Override
	public boolean deleteByList(List<Integer> idList) {
		StudentsExample example=new StudentsExample();
		Criteria criteria = example.createCriteria();
		criteria.andIdIn(idList);
		return this.dataDao.deleteByExample(example);
	}

	@Override
	public Students getStudentById(Integer id) {
		Students student=null;
		StudentsExample example=new StudentsExample();
		Criteria criteria = example.createCriteria();
		criteria.andIdEqualTo(id);
		List<Students> dataList = this.dataDao.getListByExample(example);
		if(!dataList.isEmpty()){
			student=dataList.get(0);
		}
		return student;
	}

	@Override
	public List<Students> getList() {
		StudentsExample example=new StudentsExample();
		return this.dataDao.getListByExample(example);
	}

	@Override
	public List<Map<String, Object>> getListByMap(Map<String, Object> map) {
		return this.dataDao.getListByMap(map);
	}

	@Override
	public List<Students> getListByIds(List<Integer> idList) {
		StudentsExample example=new StudentsExample();
		Criteria criteria = example.createCriteria();
		criteria.andIdIn(idList);
		return this.dataDao.getListByExample(example);
	}
	
	@Override
	public List<Students> getListByStuIds(List<String> idList) {
		StudentsExample example=new StudentsExample();
		Criteria criteria = example.createCriteria();
		criteria.andStuIdIn(idList);
		return this.dataDao.getListByExample(example);
	}

	@Override
	public boolean deleteByStuIdList(List<String> idList) {
		StudentsExample example=new StudentsExample();
		Criteria criteria = example.createCriteria();
		criteria.andStuIdIn(idList);
		return this.dataDao.deleteByExample(example);
	}
	
	@Override
	public List<Students> queryStuByRoleId(Integer roleId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("roleNo", roleId);
		return dataDao.selectStuByMap(map);
	}

	@SuppressWarnings("unchecked")
	public List<StudentsBean> queryListByState(Integer state){
		return ObjectUtil.transferList(dataDao.selectListByState(state), StudentsBean.class);
	}
}
